package com.etc.doctor.controller;


import com.etc.common.entity.BasicDoctor;
import com.etc.common.utils.Result;
import com.etc.doctor.entity.Department;
import com.etc.doctor.entity.Position;
import com.etc.doctor.service.DepartmentService;
import com.etc.doctor.service.LoginAndRegisterService;
import com.etc.doctor.service.PositionService;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/lr")
public class LoginAndRegisterController {

    @Resource
    private LoginAndRegisterService loginAndRegisterService;

    @Resource
    private DepartmentService departmentService;

    @Resource
    private PositionService positionService;

    /**
     * 登录
     *
     * @param username
     * @param password
     * @return
     */
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public Result login(@RequestParam String username, @RequestParam String password, HttpServletRequest request) throws JsonProcessingException {
        return loginAndRegisterService.login(username, password, request);
    }

    /**
     * 注册
     */
    @RequestMapping(value = "/register", method = RequestMethod.POST)
    public Result register(@RequestBody BasicDoctor doctor) throws JsonProcessingException {
        return loginAndRegisterService.register(doctor);
    }

    /**
     * 查询科室列表
     *
     * @return
     */
    @RequestMapping("/queryDp")
    public Result queryDepartmentList() {
        List<Department> list = departmentService.queryAll();
        return Result.ok(list);
    }

    /**
     * 查询职位列表
     *
     * @return
     */
    @RequestMapping("/queryPs")
    public Result queryPositionList() {
        List<Position> list = positionService.queryAll();
        return Result.ok(list);
    }

}
